The invention pertains to the synchronization of an XML document with its rendering. More particularly, the invention pertains to synchronizing a document object model (DOM) of an XML document with its object model in real time.
XML (eXtensible Markup Language) is a platform-independent programming language that is particularly adapted for use on distributed networks such as the Internet because it provides a flexible mechanism for creating common information formats and sharing both the format and the data across different software applications over the network. XML comprises markup symbols (tags) that describe the content of a file. XML is like HTML (HyperText Markup Language) in its use of markup symbols, but has at least two key distinctions over HTML. First, HTML has a specific set of defined markup symbols, whereas XML is extensible in that the markup symbols allowed in XML are unlimited and self defining. That is, while XML also has standardized markup symbols, XML programmers are not limited to the standard set of defined markup symbols, but can define new markup symbols. Secondly, whereas HTML is limited in that the tags and attributes define only how the actual content is to be displayed, XML tags and attributes can define both how the information is to be displayed (by a Web browser, for instance) and what the content is. In this specification, a basic familiarity with XML is assumed in the reader.
Because of its flexibility and readability, XML is often used as a serialization mechanism for an object model. That is, a programmer can define XML markup symbols to correspond to certain types of data and then create XML files (XML files are also called XML documents or XML pages) providing content associated with the tags and attributes. For instance, if a programmer wishes to establish a standard format for describing a type of product so that the description of products of that type can be shared across multiple applications with different platforms, the programmer can define a tag that corresponds to that product, e.g., SHIRT and attributes of that tag, each defining a property of that product, e.g., a SIZE attribute, a COLOR attribute, a MATERIAL attribute, a COST attribute, etc. The actual data content, e.g., large, red and blue stripes, cotton, $29.95, etc. is provided in the field of the attribute. The data about the product can then be transmitted over a network in a platform-independent XML page to any other computer running an XML interpreter program that is programmed to understand those particular markup symbols.
When an application program (e.g., an XML Editor) receives an XML document, several steps are performed to convert that XML document into a displayed (or rendered) page on the user""s computer monitor. In one well known scheme, first, the XML document is opened and parsed to build a document object model (DOM) containing the data. Document Object Model is a programming interface specification developed by the World Wide Web Consortium (W3C) that lets a programmer create and edit HTML and XML files as program objects. The W3C has recently issued a DOM level 2 specification which is incorporated herein by reference. A DOM essentially is a tree data structure representation of an XML file, wherein each node of the tree is an XML element, e.g., a tag, an attribute, a value, etc. After the DOM is generated, it is traversed to create an object model. Where the XML page is to be converted into a display, the object model is the model from which the display is directly rendered. Thus, the process of rendering an XML page can be considered to comprise four steps; (1) the XML document step, (2) the document object model step, (3) the object model step, and (4) the actual display step.
Several XML editor programs are presently available on the market that can be used to help generate XML pages without necessarily having in depth knowledge of XML programming. For instance, XMetal is one particular widely available XML editor produced and sold by SoftQuad Software, Ltd. of Toronto, Ontario, Canada. A typical XML editor can present to the user of the program various different views of an XML document. For instance, the editor, of course, can provide a source view of the XML source code in the actual text format. It further can generate a graphical representation of the DOM tree as well as a graphical representation of the object model. Finally, of course, it can generate the actual display view, e.g., the user interface (UI) that would be rendered when opening the page. The editor typically allows the user to interact and edit the XML document in any of those views. When the user is satisfied with an edit or set of edits, the user can then cause the edits to be converted to actual XML text.
In developing XML pages, it would be desirable for a developer using an editor program to be able to switch back and forth between a source view of the XML page (e.g., the DOM view or the XML text view) and a display view of the XML document (e.g., the actual display view or an object model view). For instance, a developer might first write an XML document or load a preexisting XML page containing some basic format and/or content and then edit it using an XML editor program in any one of the DOM view, the object model view, or the actual display view. More particularly, a developer may enter one or more edits in the DOM tree view and then wish to see how those changes affected the actual display view or the object model view. If the developer is either not satisfied with the edits or simply has more edits to enter, the developer might then enter additional edits. The developer may choose to enter these further edits in the display or object model view. Alternately, the developer may wish to return to the DOM tree view to enter the further edits.
Techniques are known for converting changes from the DOM tree view to the actual XML. Further, techniques are known for transferring changes made in an actual display view to the object model. Of course, it is also well known in the art how to convert from XML to the DOM tree and how to convert from the object model to the actual display.
The subject matter of the present invention pertains primarily to the transfer (or reflection) of edits between the display side (particularly the object model) and the source side (particularly the document object model).
In prior art editors, reflecting edits made on the display side to the DOM tree or changes made on the source side to the display side required that the XML document be completely reprocessed; that is, that the entire document be serialized and re-parsed to generate a new DOM from which a new object model is then generated in order to produce the actual display.
Thus, it should be apparent that switching between the source view and the display view requires a complete re-parsing of the XML document and is thus time consuming. In addition, developers frequently put comments in the XML text view or other views of a document and/or prefer to use certain indentation protocols for organizational purposes. However, the indentation and the comments do not form part of the object model. Thus, for example, if a developer makes a change in the object model and then wants that change to be fully synchronized across the XML code, DOM and object model, the XML editor will need to completely serialize and re-parse the XML file to create a new instance of the DOM, object model and actual display. Since the object model does not understand the indentations or the comments, they are not preserved upon re-parsing. This can be very annoying to the developer. Even further, selections and state information which the user may have entered by interacting with a display view, also will be lost.
Accordingly, it is an object of the present invention to provide an improved XML editor.
It is another object of the present invention to provide an improved method and apparatus for synchronizing an object model to a DOM and vice versa.
The invention is a method and apparatus for synchronizing a document object model (DOM) with the corresponding object model and vice versa. The method and apparatus of the present invention is particularly useful for XML editors because changes made on the source side (and particularly the DOM) or the display side (and particularly the object model) are reflected to the other without serializing and re-parsing the entire XML file, but instead rewriting only the particular DOM node or object model property that is changed.
In accordance with the invention, a map is maintained of the information needed to reflect DOM node information to a corresponding object model property and reflect object model property information to the corresponding DOM node. Such map information typically would include information such as the tags and attributes of each node. The map can be organized as a plurality of collections of data items (herein termed map info objects), each collection pertaining to one adapter.
In accordance with the invention, a plurality of adapter software modules are created upon parsing of an XML document, each adapter responsible for reflecting changes made to a subset of DOM nodes to the corresponding object model properties and vice versa. Each adapter is capable of synchronizing in either direction, i.e., it can reflect changes made in the DOM to the object model and changes made in the object model to the DOM. Each adapter is responsible for a small portion of the document. Therefore, each edit can be reflected between the object model and the DOM quickly without re-parsing or iterating over the entire document.
In accordance with the invention, when a DOM is initially generated from an XML document, a plurality of DOM/object-model adapters are created from the map information. The portion of the document for which each adapter is responsible should be selected such that each adapter is relatively simple. For example, a different adapter is responsible for each node of the DOM tree.
Since a change to a DOM node or an object model property can have ripple effects to other, child nodes or child properties, the map includes information indicating any other adapters responsible for child nodes or properties that also need to be updated (hereinafter child adapters). Thus, part of the process of creating an adapter is registering with the pertinent DOM node(s) or object model property(ies), respectively, those changes that should be reported to that adapter.
Thereafter, whenever an object model property is updated, notification is sent to the corresponding DOM/object model adapter. That adapter iterates through the map list and, for each info object in the list, reflects the change to corresponding DOM node(s). If the change has ripple effects to other object model properties for which a different adapter is responsible (a child adapter), one of the info objects in the list for the parent adapter will so indicate and that child adapter will be called and it will iterate through its map list reflecting the changes to the DOM. Depending on the particular change, the child adapter may first need to be created or it may already have been created and merely need updating.
In the opposite direction, when a DOM node is updated, essentially the same process is performed in reverse. Particularly, the DOM-to-object model adapter is notified of the change and that adapter retrieves the map info object(s) for the corresponding node. For each map info object for that adapter, the corresponding object model property is updated (or created, if necessary) including the updating or creation of new child adapters, if necessary.
Thus, in accordance with the invention, the source view can be synchronized to the display view and vice versa on the fly in real time without the need to serialize and re-parse the entire document. In an XML editing environment, this allows a developer to keep both the display view and the source view open simultaneously and synchronized to each other.